-- 复仇铁矢
local fuchoutieshi = fk.CreateSkill {
    name = "mcdh_fuchoutieshi",
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

fuchoutieshi:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) and target.phase == Player.Finish then
            local room = player.room
            local logic = room.logic
            local ids = {}
            local count = 0
            logic:getEventsOfScope(GameEvent.MoveCards, 999, function(e)
                local checkIds = {}
                local checkCount = 0
                for _, move in ipairs(e.data) do
                    if move.toArea == Card.DiscardPile then
                        for _, info in ipairs(move.moveInfo) do
                            if move.moveReason == fk.ReasonDiscard and move.from == target then
                                if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                                    table.insertIfNeed(checkIds, info.cardId)
                                end
                            end
                        end
                    end
                end
                checkIds = U.moveCardsHoldingAreaCheck(room, checkIds, e.id)
                table.insertTableIfNeed(checkIds,ids)
                count = count + #checkIds
            end, Player.HistoryTurn)
            return count >= 2
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local cards =player:getTableMark("mcdh_fuchoutieshi_card-turn")
        if #cards > 0 then
            room:askForUseRealCard(player, {cards}, self.name, "#mcdh_fuchoutieshi-invoke", { bypass_times = true,bypass_distances = true }, true, true)
        end
        end
})

Fk:loadTranslationTable {
    ["mcdh_fuchoutieshi"] = "仇矢",
    [":mcdh_fuchoutieshi"] = "『复仇铁矢』<br>一名角色的结束阶段，若本回合其因弃置而失去至少两张牌，你可以使用一张弃牌堆中本回合该角色因弃置而进入弃牌堆的牌（无距离次数限制）。",
    ["#mcdh_fuchoutieshi-invoke"] = "复仇铁矢：使用一张弃牌堆中本回合置入的牌",
    ["mcdh_fuchoutieshi_viewas"] = "复仇铁矢"
}

return fuchoutieshi